class Student:
    def __init__(self, student_id, name, preferences):
        self.student_id = student_id
        self.name = name
        self.preferences = preferences  # 这个学生的导师志愿列表

class Mentor:
    def __init__(self, mentor_id, name):
        self.mentor_id = mentor_id
        self.name = name

# 初始化学生和导师
students = [
    Student(1, "李明", [1, 2, 3]),  # 志愿1是导师1，志愿2是导师2，志愿3是导师3
    Student(2, "王芳", [1, 3, 2]),
    Student(3, "张伟", [2, 1, 3]),
]

mentors = [
    Mentor(1, "张教授"),
    Mentor(2, "李教授"),
    Mentor(3, "王教授"),
]

# 学生与导师的映射
student_mentor_map = {mentor.mentor_id: [] for mentor in mentors}

def assign_students_to_mentors():
    for student in students:
        assigned = False
        for preference in student.preferences:
            # 检查该导师是否已选择 3 个学生
            if len(student_mentor_map[preference]) < 3:
                # 检查该学生是否已被其他导师选择
                if student.student_id not in student_mentor_map[preference]:
                    student_mentor_map[preference].append(student.student_id)
                    print(f"学生 {student.name} 被成功分配给导师 {mentors[preference - 1].name}。")
                    assigned = True
                    break  # 学生找到导师后停止继续寻找
        if not assigned:
            print(f"学生 {student.name} 无法被分配给任何导师。")

# 调用分配函数
assign_students_to_mentors()

# 输出每位导师的选择
for mentor_id, assigned_students in student_mentor_map.items():
    print(f"导师 {mentors[mentor_id - 1].name} 的学生: {assigned_students}")